package com.example.specialeffect;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
public class TranslateView extends View {
    public TranslateView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint=new Paint();
        Bitmap bitmap= BitmapFactory.decodeResource(this.getResources(),R.drawable.husky);
        Matrix matrix=new Matrix();
        matrix.setTranslate(0,0);    //水平和垂直方向平移的像素数
        canvas.drawBitmap(bitmap,matrix,paint);
    }
}
